package com.cy.service;

import com.cy.mapper.UserMapper;
import com.cy.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author : 残影
 * @Date: 2020/7/22 11:23
 */
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public User queryById(Long id){
        return userMapper.selectByPrimaryKey(id);
    }

    /**
     * 新增保存用户
     * @param user
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveUser(User user){
        System.out.println("新增用户... ");
        //选择性新增；如果属性为空则该属性不会出现在insert语句上
        userMapper.insertSelective(user);
        int i = 1/0;
    }
}
